package com.fzz.serviceImpl;

import com.fzz.dao.AdminMapping;
import com.fzz.domain.Admin;
import com.fzz.domain.User;
import com.fzz.domain.View;
import com.fzz.service.AdminService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;

import java.util.List;

@Component
public class AdminServiceImpl implements AdminService {


    @Autowired
    private AdminMapping adminMapping;

    //管理员登录
    @Override
    public Admin adminLogin(String adminName, String password) {
        return adminMapping.adminLogin(adminName,password);
    }

    //管理员修改信息
    @Override
    public Integer adminUpdate(Admin admin) {
        return adminMapping.adminUpdate(admin);

    }

    //用户信息分页查询
    @Override
    public PageInfo<User> selectUserWithPage(Model model,Integer id,String username,Integer page, Integer count) {
        PageHelper.startPage(page,count);
        List<User> userWithPageList = adminMapping.selectUserWithPage(id,username);
        PageInfo<User> pageInfo=new PageInfo<>(userWithPageList);
        model.addAttribute("pageInfo",pageInfo);
        return pageInfo;
    }


    //根据id和用户名查询
    @Override
    public User selectUserById(Integer id) {

        return adminMapping.seleteUserById(id);
    }

    //修改用户信息
    @Override
    public Integer editUserInfo(User user) {
        return adminMapping.editUserInfo(user);
    }

    //删除用户信息
    @Override
    public Integer deleteUserInfoById(Integer id) {
        return adminMapping.deleteUserInfoById(id);
    }


}
